package com.itheima.app.manager;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MovementMQManager {

    //针对动态的操作
    public static final Integer MOVEMENT_PUBLISH = 1;// 发动态
    public static final Integer MOVEMENT_BROWSE = 2;// 浏览动态
    public static final Integer MOVEMENT_LIKE = 3;// 点赞
    public static final Integer MOVEMENT_LOVE = 4;// 喜欢
    public static final Integer MOVEMENT_COMMENT = 5;// 评论
    public static final Integer MOVEMENT_DISLIKE = 6;// 取消点赞
    public static final Integer MOVEMENT_DISLOVE = 7;// 取消喜欢

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Reference
    private MovementService movementService;

    //向tanhua-recommend发送MQ消息
    //谁对什么内容进行了什么操作
    public void sendMsg(String movementId,Integer type) {

        //获取当前登录用户
        Long userId = UserHolder.getId();
        //查询动态
        Movement movement = movementService.findMovement(movementId);
        //构建消息对象
        Map map = new HashMap<>();
        map.put("userId", userId);
        map.put("type", type);
        map.put("pid", movement.getPid());
        //发送MQ消息
        rocketMQTemplate.convertAndSend("tanhua-recommend-161",map);
    }
}
